const CracoLessPlugin = require('craco-less');
const px2rem = require("postcss-px2rem-exclude");
const path = require("path");
const resolve = dir => path.resolve(__dirname, dir);
module.exports = {
  devServer: {
    proxy: {
      '/api': {
        target: 'https://partner-h5-pre.edsmall.com',
        changeOrigin: true,
        // pathRewrite: {
        //   "^/api": ''
        // }
      }
    },
  },
  webpack: {
    alias: {
      '@': resolve("src"),
    },
    configure: (webpackConfig, { env, paths }) => {
      if (env == "production") {
        paths.appBuild = resolve("dist");
        webpackConfig.output.path = resolve("dist");
        // webpackConfig.output.publicPath="/test"
        webpackConfig.devtool = "(none)"
      }
      // console.log("env:", env)
      // console.log("paths:", paths)
      // console.log("webpackConfig:", webpackConfig)
      return webpackConfig;
    }
    // configure:{
    //   path:path.resolve(__dirname, "dist"), 
    //   // sourcemap: false
    // },
    // build: {
    //   sourcemap: false
    // }
  },
  // style: {
  //   postcss: {
  //     plugins: [
  //       // px2rem({
  //       //   remUnit: 37.5,
  //       //   // propList: ['and-'],
  //       //   // exclude: /antd/i
  //       // })
  //     ]
  //   }
  // },
  // 按需引入antd
  babel: {
    plugins: [['import', {
      libraryName: 'antd',
      libraryDirectory: 'es',
      style: true,
    }]],
  },
  plugins: [
    // {
    //   plugin: BabelPlugin,
    //   options: {
    //     "libraryName": "antd",
    //     "libraryDirectory": "es",
    //     "style": true //设置为true即是less
    //   }
    // },
    // 修改默认antd主题

    {
      plugin: CracoLessPlugin,
      options: {
        lessLoaderOptions: {
          lessOptions: {
            modifyVars: { '@primary-color': '#1DA57A' },
            javascriptEnabled: true,
            sourceMap: false
          },
        
        },
        // cssLoaderOptions: {
        //   modules: {
        //     localIdentName: '[local]__[hash:base64:5]',
        //     // 回调必须返回 `local`，`global`  默认global
        //     mode: (resourcePath) => {
        //       if (/(modules|local)\.(less|css)$/i.test(resourcePath)) {
        //         return 'local'
        //       }
        //       return 'global'
        //     }
        //   }
        // },
      },
    },
    {
      // plugin: require('craco-plugin-scoped-less'),
      plugin: require('craco-plugin-scoped-css'),
    },
    {
      plugin: require('craco-scoped-less'),
    }
  ],
};